import http from "assets/api/http";

let baseUrl = 'http://localhost:8080';

export const getCategories = () => {
    if (process.client) {
        return http.requestGet("/portal/article/categories");
    } else {
        return http.requestGet(baseUrl + "/portal/article/categories");
    }
}

export const getTopArticle = (_page, _size) => {
    if (process.client) {
        return http.requestGet("/portal/article/top/" + _page + "/" + _size);
    } else {
        return http.requestGet(baseUrl + "/portal/article/top/" + _page + "/" + _size);
    }
}

export const getArticles = (_page, _size) => {
    if (process.client) {
        return http.requestGet("/portal/article/list/" + _page + "/" + _size);
    } else {
        return http.requestGet(baseUrl + "/portal/article/list/" + _page + "/" + _size);
    }
}

export const getArticleLabels = (_count) => {
    if (process.client) {
        return http.requestGet("/portal/article/label/" + _count);
    } else {
        return http.requestGet(baseUrl + "/portal/article/label/" + _count);
    }
}

export const getArticlesByCategoryId = (_categoryId, _page, _size) => {
    if (_categoryId === '') {
        return getArticles(_page, _size);
    } else {
        if (process.client) {
            return http.requestGet("/portal/article/list/" + _categoryId + "/" + _page + "/" + _size);
        } else {
            return http.requestGet(baseUrl + "/portal/article/list/" + _categoryId + "/" + _page + "/" + _size);
        }
    }
}

export const getArticleDetail = (_articleId) => {
    if (process.client) {
        return http.requestGet("/portal/article/" + _articleId);
    } else {
        return http.requestGet(baseUrl + "/portal/article/" + _articleId);
    }
}

export const getRecommendArticleByArticleId = (_id, _size) => {
    if (process.client) {
        return http.requestGet("/portal/article/recommend/" + _id + "/" + _size);
    } else {
        return http.requestGet(baseUrl + "/portal/article/recommend/" + _id + "/" + _size);
    }
}
